// @ts-ignore
/* eslint-disable */
import { request as umiRequest, getDvaApp } from 'umi';
import { getToken } from './auth';

export async function request(options: { url: string; [key: string]: any }) {
  const {url, headers, ...restProps} = options
  const {requestType} = restProps
  return umiRequest(url, {
    headers: {
      ...(requestType === 'form' ? {} : {'Content-Type': 'application/json'}),
      ...(headers || {})
    },
    ...(restProps || {}),
  });
}

export async function requestAuth(options: { url: string; [key: string]: any }) {
  const { _store } = getDvaApp() || {};
  const token = _store?.getState()?.user?.token || getToken();
  const {url, headers, ...restProps} = options
  const {requestType} = restProps
  return umiRequest(url, {
    headers: {
      'Authorization': token,
      ...(requestType === 'form' ? {} : {'Content-Type': 'application/json'}),
      ...(headers || {})
    },
    ...(restProps || {}),
  });
}
